package com.example.practice2023.service;

import com.example.practice2023.mapper.ShopMapper;
import com.example.practice2023.pojo.Shop;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.sql.Timestamp;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * ClassName: ShopService
 * Package: com.example.practice2023.service
 * Description:
 *
 * @Author hyx
 * @Create 2023/7/4 1:32
 * @Version 1.0
 */
@Service
public class ShopService {
@Resource
 private ShopMapper shopMapper;

    public Map<String, Object> selectShopByName(String shopname) {
        Shop shop = shopMapper.selectShopByName(shopname);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "基于条件查询成功");
        map.put("data", shop);
        return map;
    }
    public Map<String, Object> select() {
        List<Shop> shop = shopMapper.select();
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "基于条件查询成功");
        map.put("data", shop);
        return map;
    }
    //ying
    //    测试
    public Map<String,Object> selectById(Integer id) {
        Map<String, Object> map = new HashMap<>();
        Shop shop = shopMapper.selectById(id);
        map.put("code", 200);
        map.put("msg", "查询成功");
        map.put("data", shop);
        return map;
    }
    //    新增
    public Map<String, Object> insertShop(Shop shop) {
        Map<String, Object> map = new HashMap<>();

        shop.setShopCreateTime(new Timestamp(System.currentTimeMillis()));
        shopMapper.insertShop(shop);
        map.put("code", 200);
        map.put("msg", "插入用户成功");
        map.put("data", shop);
        return map;
    }
    //删除
    public Map<String, Object> deleteById(Integer shopId) {
        Map<String, Object> map = new HashMap<>();
        shopMapper.deleteById(shopId);
        map.put("code", 200);
        map.put("msg", "删除店铺成功");
        map.put("id", shopId);
        return map;
    }
    //修改
    public Map<String, Object> updateById(Shop shop) {
        Map<String, Object> map = new HashMap<>();
        shopMapper.updateById(shop);
        map.put("code", 200);
        map.put("msg", "更新用户成功");
        map.put("data", shop);
        return map;
    }
    //分页查询
    public Map<String, Object> selectByPage(int page,int limit,Shop shop) {
        int index = (page - 1)*limit;

        List<Shop> shopList = shopMapper.selectByPage(index,limit,shop.getShopName(),shop.getShopStatus());
        Map<String, Object> map = new HashMap<>();
        map.put("code", 0);
        map.put("msg", "分页查询成功");
        map.put("count", shopMapper.selectAllCount(shop.getShopName(),shop.getShopStatus()));
        map.put("data", shopList);
        return map;
    }
}
